﻿Public Partial Class QuickImageUpload
    Inherits System.Web.UI.Page

    'NOTE: This page is a temporary fix to help administer the system until 
    ' the fully developed administration system is here


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not Page.IsPostBack Then
            ddlImages.Items.Clear()

            Dim manager As New BLL.ImageManager

            ddlImages.DataSource = manager.GetAllImages()
            ddlImages.DataBind()

        End If

    End Sub

    Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpload.Click
        Dim intLength As Integer

        Dim arrContent As Byte()

        If fuBanner.PostedFile Is Nothing Then

            Exit Sub

        Else

            Dim fileName As String = fuBanner.PostedFile.FileName '.Substring(FileUpload1.PostedFile.FileName.LastIndexOf("/") + 1)

            Dim ext As String = fileName.Substring(fileName.LastIndexOf("."))

            ext = ext.ToLower.Replace(".", "")


        End If



        intLength = Convert.ToInt32(fuBanner.PostedFile.InputStream.Length)

        ReDim arrContent(intLength)



        fuBanner.PostedFile.InputStream.Read(arrContent, 0, intLength)


        ' Get image selected from database
        Dim manager As New BLL.ImageManager

        Dim image As Domain.dnc_Image = manager.GetImageByID(Convert.ToInt32(ddlImages.SelectedValue))

        image.Image = arrContent

        manager.UpdateImage(image)

    End Sub
End Class